package com.example.gokuplayalong.bases.mobsdk;

import android.annotation.SuppressLint;
import android.content.Context;

import com.example.gokuplayalong.bases.tools.Logger;
import com.mob.pushsdk.MobPush;
import com.mob.pushsdk.MobPushCustomMessage;
import com.mob.pushsdk.MobPushNotifyMessage;
import com.mob.pushsdk.MobPushReceiver;

import java.util.HashMap;
import java.util.Map;

public class MobSdkMobPush {
    static MobPushReceiver mobPushReceiver;

    public static void init() {
        mobPushReceiver = new MobPushReceiver() {
            @SuppressLint("ObsoleteSdkInt")
            @Override
            public void onCustomMessageReceive(Context context, MobPushCustomMessage message) {
                //接收到自定义消息（透传消息）
                Map<String, String> map = new HashMap<>(message.getExtrasMap());
                Logger.d("收到透传消息 ：" + map.toString());

            }

            @Override
            public void onNotifyMessageReceive(Context context, MobPushNotifyMessage message) {
                //接收到通知消息
            }

            @Override
            public void onNotifyMessageOpenedReceive(Context context, MobPushNotifyMessage
                    message) {
                //通知被点击事件


            }

            @Override
            public void onTagsCallback(Context context, String[] tags, int operation,
                                       int errorCode) {
                //标签操作回调
                //tags: RegistrationId已添加的标签
                //operation: 0获取标签 1设置标签 2删除标签
                //errorCode: 0操作成功 非0操作失败

            }

            @Override
            public void onAliasCallback(Context context, String alias, int operation,
                                        int errorCode) {
                //别名操作回调
                //alias: RegistrationId对应的别名
                //operation: 0获取别名 1设置别名 2删除别名
                //errorCode: 0操作成功 非0操作失败
            }

        }
        ;
        addPushReceiver();

    }

    public static void addPushReceiver() {
        MobPush.addPushReceiver(mobPushReceiver);
    }

    public static void removePushReceiver() {
        if (mobPushReceiver != null) MobPush.removePushReceiver(mobPushReceiver);

    }
}
